<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')


      this.chart.setOption({

        title : {
        text: '车辆违章类型',
        x:'center'
   
      },
      tooltip: {
        trigger: 'item' // 触发类型，'item' 表示数据项图形触发，'axis' 表示坐标轴触发
    }, 
      dataset: {
      source: [
        [ '金额', 'product'],
        [ 58212, '无证经营'],
        [ 78254, '假牌套牌'],
        [ 41032, '未密闭运输'],
        [ 12755, '超载超限'],
        [ 20145, '沿途遣撒']
      ]
  },
  grid: { containLabel: true , left: '5%'},
  xAxis: { name: '金额' },
  yAxis: { type: 'category' },
  
  series: [
    {
      type: 'bar',
      encode: {
        // Map the "amount" column to X axis.
        x: '金额',
        // Map the "product" column to Y axis
        y: 'product'
      }
    }
  ]
      })}
  
  }
}
</script>
